1 using System;
2 using
UnityEngine;
3 #
if UNITY_EDITOR
4 using
UnityEditor;
5 #endif

6
7 namespace
UnityStandardAssets.Utility
8 {
9 #
if UNITY_EDITOR
10
11     
[ExecuteInEditMode]
12 #endif
13     
public class PlatformSpecificContent : MonoBehaviour
14     {
15         
private enum BuildTargetGroup
16         {
17             Standalone,
18             Mobile
19         }
20
21         [SerializeField]
private BuildTargetGroup m_BuildTargetGroup;
22         [SerializeField]
private GameObject[] m_Content = new GameObject[0];
23         [SerializeField]
private MonoBehaviour[] m_MonoBehaviours = new MonoBehaviour[0];
24         [SerializeField]
private bool m_ChildrenOfThisObject;
25
26 #
if !UNITY_EDITOR
27     
void OnEnable()
28     {
29         CheckEnableContent();
30     }
31 #endif
32
33 #
if UNITY_EDITOR
34
35         
private void OnEnable()
36         {
37             EditorApplication.update += Update;
38             EditorUserBuildSettings.activeBuildTargetChanged += Update;
39         }
40
41
42         
private void OnDisable()
43         {
44             EditorApplication.update -= Update;
45             EditorUserBuildSettings.activeBuildTargetChanged -= Update;
46         }
47
48         
private void Update()
49         {
50             CheckEnableContent();
51         }
52 #endif
53
54
55         
private void CheckEnableContent()
56         {
57 #
if (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_TIZEN || UNITY_STV )
58         
if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
59         {
60             EnableContent(
true);
61         }
else {
62             EnableContent(
false);
63         }
64 #endif
65
66 #
if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_TIZEN || UNITY_STV )
67             
if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
68             {
69                 EnableContent(
false);
70             }
71             
else
72             {
73                 EnableContent(
true);
74             }
75 #endif
76         }
77
78
79         
private void EnableContent(bool enabled)
80         {
81             
if (m_Content.Length > 0)
82             {
83                 
foreach (var g in m_Content)
84                 {
85                     
if (g != null)
86                     {
87                         g.SetActive(enabled);
88                     }
89                 }
90             }
91             
if (m_ChildrenOfThisObject)
92             {
93                 
foreach (Transform t in transform)
94                 {
95                     t.gameObject.SetActive(enabled);
96                 }
97             }
98             
if (m_MonoBehaviours.Length > 0)
99             {
100                 
foreach (var monoBehaviour in m_MonoBehaviours)
101                 {
102                     monoBehaviour.enabled = enabled;
103                 }
104             }
105         }
106     }
107 }


Gõ tìm kiếm nhanh...